<template>
    <div class="login">
        <div class="loginTop">欢迎登陆</div>
        <div class="loginContent">
            <input
                type="text"
                name="phone"
                class="phone"
                v-model="phone"
                placeholder="请输入手机号码"
            />
            <input
                type="text"
                name="password"
                class="password"
                v-model="password"
                placeholder="请输入密码"
            />
            <button class="btn" @click="Login">登录</button>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            phone: "",
            password: "",
        };
    },
    methods: {
        async Login() {
            let res = await this.$store.dispatch("getLogin", {
                phone: this.phone,
                password: this.password,
            });
            if (res.code === 200) {
                //如果返回的code等于200，说明登录成功，就跳转个人中心页面
                this.$router.commit("updateIsLogin", true);
                this.$router.push("/infoUser");
            } else {
                alert("手机号码或者密码错误");
                this.password = "";
            }
        },
    },
};
</script>
<style lang="less" scoped>
.login {
    width: 100%;
    height: 13.34rem;
    padding: 0.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: pink;
    .loginTop {
        margin-top: 1rem;
        font-size: 1rem;
        color: #fff;
    }
    .loginContent {
        width: 100%;
        height: 6rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-around;
        margin-top: 2rem;
        .phone,
        .password {
            width: 5rem;
            height: 0.7rem;
            border: 0.02rem solid #999;
        }
        .btn {
            width: 2rem;
            height: 0.6rem;
        }
    }
}
</style>